package gui;

import java.io.IOException;

import application.Fassade;
import application.Move;

public class GUIController {
	
	private static GUIController instance = null;
	
	private GameFrame   gameFrame;
	private StartPanel  startPanel;
	private GamePanel   gamePanel;
	private ManualPanel manualPanel;
	private String 		position[][];
	private String		zugkontrolle;
	private Fassade 	fassade;
	
	private GUIController(){
		
		gameFrame   =    new GameFrame();
		startPanel  =   new StartPanel();
		gamePanel   =    new GamePanel();
		manualPanel =  new ManualPanel();
		fassade		= 	Fassade.getinstance();
		fassade.ziehen.addObserver(gamePanel);
		
	}
	
	public static GUIController getInstance(){
		if (instance == null){
			instance = new GUIController();
		}
		return instance;
	}
	
	public void exitGame(){
		System.exit(0);
	}
	
	public void initGameGUI(){
		gameFrame.setVisible(true);
		gameFrame.add(startPanel);
		
	}
	
	public void switchStartToGame(){
		gameFrame.remove(startPanel);
		gameFrame.add(gamePanel);
		gameFrame.validate();
		gameFrame.repaint();
	}

	public void switchStartToManual() {
		gameFrame.remove(startPanel);
		gameFrame.add(manualPanel);
		gameFrame.validate();
		gameFrame.repaint();
	}

	public void switchManualToStart() {
		gameFrame.remove(manualPanel);
		gameFrame.add(startPanel);
		gameFrame.validate();
		gameFrame.repaint();
	}
	
	public void initialisiereSpiel(String attackerName, String defenderName, boolean isAttackerHuman, boolean isDefenderHuman, int kiDenkzeit){
		Fassade.getinstance().initialisiereSpiel(attackerName, defenderName, isAttackerHuman, isDefenderHuman, kiDenkzeit);
	}
	
	public String zugKontrolle(Move zug) throws IOException{
		return Fassade.getinstance().zugKontrolle(zug);
	}
	
	public String[][] getPositions(){
		this.position = Fassade.getinstance().getPositions();
		return position;
	}

}